package web.Courts;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import entity.CourtsBean;
import services.CourtsServiceAll;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getCourtsAll")
public class GetCourtsAll extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        List<CourtsBean> list = new CourtsServiceAll().getCourtsAll();
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeNulls();
        Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        String json = gson.toJson(list);
        resp.getWriter().println(json);
    }
}
